package cn.seecoder.ai.controller;

import cn.seecoder.ai.model.vo.AnalysisPipelineVO;
import cn.seecoder.ai.model.vo.AnalysisVisualizationVO;
import cn.seecoder.ai.model.vo.ResultVO;
import cn.seecoder.ai.service.AnalysisPipelineService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author DingXiaoyu
 * @date 2023/4/13 15:30
 */

@Slf4j
@RestController
@RequestMapping("${apiPrefix}/analysis/pipelines")
public class AnalysisPipelineController {

    @Autowired
    AnalysisPipelineService analysisPipelineService;

    @ApiOperation("创建流水线")
    @PostMapping
    public ResultVO<AnalysisPipelineVO> addPipeline(@RequestBody AnalysisPipelineVO analysisPipelineVO){
        return ResultVO.buildSuccess(analysisPipelineService.addPipeline(analysisPipelineVO));
    }

    @ApiOperation("使用流水线")
    @PostMapping("/{pipelineId}")
    public ResultVO<AnalysisVisualizationVO> usePipeline(@PathVariable(value = "pipelineId")Integer pipelineId,
                                                         @RequestParam(value = "fileId")Integer fileId){
        try {
            return ResultVO.buildSuccess(analysisPipelineService.usePipeline(pipelineId,fileId));
        }catch (Exception e){
            return ResultVO.buildFailure("选择特征列数量或者类型错误");
        }

    }

    @ApiOperation("查看流水线详细信息")
    @GetMapping("/{pipelineId}")
    public ResultVO<AnalysisPipelineVO> getPipeline(@PathVariable(value = "pipelineId")Integer pipelineId){
        return ResultVO.buildSuccess(analysisPipelineService.getPipeline(pipelineId));
    }

    @ApiOperation("删除流水线")
    @DeleteMapping("/{pipelineId}")
    public ResultVO<Boolean> deletePipeline(@PathVariable(value = "pipelineId")Integer pipelineId){
        return ResultVO.buildSuccess(analysisPipelineService.deletePipeline(pipelineId));
    }

    @ApiOperation("查看流水线详细信息")
    @GetMapping("/all/{userId}")
    public ResultVO<List<AnalysisPipelineVO>> getPipelines(@PathVariable(value = "userId")Integer userId){
        return ResultVO.buildSuccess(analysisPipelineService.getPipelines(userId));
    }
}
